package org.example.laboratorymanagement.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.laboratorymanagement.pojo.Admin;
import org.example.laboratorymanagement.pojo.Result;
import org.example.laboratorymanagement.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理操作类
 */
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/admins")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result adminLogin(@RequestBody Admin admin) { //@RequestBody
        log.info("管理员登录：{}", admin);
        Admin a = adminService.login(admin);

        if (a != null){
            return Result.success(a);
        }

        return Result.error("管理员：用户名或密码错误");

    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        log.info("获取用户名ID：{}", id);
        Admin a = adminService.selectctById(id);
        return Result.success(a);
    }

    @PutMapping
    public Result update(@RequestBody Admin admin){
        log.info("修改管理员：{}", admin);
        adminService.update(admin);
        return Result.success();
    }

}
